package org.example.project3.Controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.example.project3.DTO.ArticleDTO;
import org.example.project3.DTO.PageQueryDTO;
import org.example.project3.Result_.Result;
import org.example.project3.Service.ArticleServiceImpl;
import org.example.project3.VO.ArticleVO;
import org.example.project3.VO.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/bigevent/article")
public class ArticleController {
    @Autowired
    private ArticleServiceImpl articleService;

    /**
     * 条件分页查询文章
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public Result search(PageQueryDTO dto){
        log.info("分页查询的dto:{}",dto);
        PageVO vo = articleService.search(dto);
        return Result.success(vo);
    }

    /**
     * 发布文章
      * @param dto
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody ArticleDTO dto){
        log.info("发布文章的dto:{}",dto);
        articleService.add(dto);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result delete(String id){
        log.info("删除的文章id:{}",id);
        articleService.delete(Integer.parseInt(id));
        return Result.success();
    }

    @GetMapping
    public Result getByid(String id){
        log.info("查询的文章id:{}",id);
         ArticleVO vo  = articleService.getByid(Integer.parseInt(id));
        return Result.success(vo);
    }

    @PutMapping("/edit")
    public Result edit(@RequestBody ArticleDTO dto){
        log.info("待编辑的dto:{}",dto);
        articleService.edit(dto);
        return Result.success();
    }
}
